//
//  SwitchButtonWithTitle.swift
//  GreenDeal
//
//  Created by Moennig Q on 2023/3/4.
//

import UIKit
import SnapKit
class SwitchButtonWithTitle: UIView {
    let descripLabel = ContentLabel()
    lazy var switchBtn: SwitchButton = {
        let view = SwitchButton()
        return view
    }()
    //IB init
    required init?(coder aDecoder: NSCoder) {
        super.init(coder:aDecoder)
    }
    init(title: String, hasBorder: Bool = true) {
        super.init(frame: CGRect.zero)
        self.setUpView(title: title, hasBorder: hasBorder)
    }
    func setUpView(title: String, hasBorder: Bool) {
        //switch btn
        self.addSubview(switchBtn)
        switchBtn.snp.makeConstraints { make in
            make.top.equalTo(Constant.TopBottomMargin)
            make.right.equalTo(-Constant.LeftRightMargin)
            make.size.equalTo(SwitchButton.size)
            make.bottom.equalTo(-Constant.TopBottomMargin)
        }
        //是否带border
        if hasBorder {
            self.backgroundColor = UIColor(hexStr: "#F0F6F3FF")
            self.layer.borderColor = UIColor(hexStr: "#005D2D66").cgColor
            self.layer.borderWidth = 1
            self.layer.cornerRadius = Constant.StandardCornerRadius
            self.clipsToBounds = true
            //isConnectedToGridLabel
            descripLabel.numberOfLines  =  0
            descripLabel.text = title
            descripLabel.textAlignment = .left
            self.addSubview(descripLabel)
            descripLabel.snp.makeConstraints { make in
                make.left.equalTo(Constant.LeftRightMargin)
                make.right.equalTo(switchBtn.snp.left)
                make.height.greaterThanOrEqualTo(0)
                make.centerY.equalToSuperview()
            }
        }else{
            //isConnectedToGridLabel
            descripLabel.numberOfLines  =  0
            descripLabel.text = title
            descripLabel.textAlignment = .left
            self.addSubview(descripLabel)
            descripLabel.snp.makeConstraints { make in
                make.left.equalToSuperview()
                make.right.equalTo(switchBtn.snp.left)
                make.height.greaterThanOrEqualTo(0)
                make.centerY.equalToSuperview()
            }
        }
        self.switchBtn.switchOn(false)
    }
}
